﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Express.Core.Responses;

namespace Express.Core.Controls
{
    public class ItemListAdapter : BaseAdapter<TraceInfo>
    {
        List<TraceInfo> items;
        Activity context;

        public ItemListAdapter(Activity context, List<TraceInfo> items) : base()
        {
            this.items = items;
            this.context = context;
        }

        public override long GetItemId(int position)
        {
            return position;
        }
        public override TraceInfo this[int position]
        {
            get { return items[position]; }
        }
        public override int Count
        {
            get { return items.Count; }
        }

        /// <summary>
        /// 会循环执行这个方法
        /// </summary>
        /// <param name="position"></param>
        /// <param name="convertView"></param>
        /// <param name="parent"></param>
        /// <returns></returns>
        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            var item = items[position];
            var view = convertView;
            if (view == null)
            {
                //使用自订Layout
                view = context.LayoutInflater.Inflate(Resource.Layout.ItemList, null);
            }
            view.FindViewById<TextView>(Resource.Id.desc).Text = item.AcceptStation;//显示绑定的字段
            view.FindViewById<TextView>(Resource.Id.dateTime).Text = item.AcceptTime;//显示绑定的字段

            return view;
        }
    }
}